	
	//검색기간
	function clsMyMileageCalendar(){
		this.listData = null;
		this._HTMLDom = null;
		this._init();
	}
	
	clsMyMileageCalendar.prototype = {
		_init: function(){
			var $layer = $("section#my_mileage_view>section div.my_mileage_search");
			this._HTMLDom = {
				"$layer": $layer	
			}			
			this.listData = [1,3,6,12]
			var d = new Date();
			var year = d.getFullYear();
			
			//초기 날짜 설정 (시작날짜 : 오늘-1달, 종료날짜 : 오늘)
			for(var i=0;i<$layer.find("div.date select:eq(0) option").length;++i){
				if($layer.find("div.date select:eq(0) option").eq(i).html() == year) $layer.find("div.date select:eq(0) option").eq(i).prop("selected",true);
			}
			$layer.find("div.date select:eq(1) option").eq(d.getMonth()-1).prop("selected",true);
			$layer.find("div.date select:eq(2) option").eq(d.getDate()-1).prop("selected",true);
			
			$layer.find("input:radio:eq(0)").prop("checked",true).checkboxradio("refresh");
			
			$layer.find("select").selectmenu("refresh");
		}	
		, getStartDt: function(){
			var $layer = this._HTMLDom["$layer"].find("select");
			var result = "";
			for(var i=0;i<3;++i){
				result += $layer.eq(i).find("option:selected").html();
			}
			return result;
		}
		, getTerm: function(){
			var radios = this._HTMLDom["$layer"].find("input:radio");
			
			var n = radios.index(radios.filter(":checked"));
			
			return this.listData[n];
		}
		, $getBtnRadio: function(){
			return this._HTMLDom["$layer"].find("input:radio");	
		}
	}
	
	//마일리지정보
	function clsMyMilegeView(){
		this.listData = null;
		this._HTMLDom = null;
		this._init();
	}
	
	clsMyMilegeView.prototype = {
		_init: function(){
			var $layer = $("section#my_mileage_view>section div.my_mileage_list");
			this._HTMLDom = {
				"$layer": $layer	
				, "$element": $layer.find("ul li:first")
			}
			
			$layer.find("ul").empty();
		}	
		, setList: function(thisData){
			if(!this.listData) this.listData = [];			
			this.push(thisData)
		}
		, push: function(thisData){			
			var thisClass = this;
			var $element = this._HTMLDom["$element"];
			var $tmp = [];
			
			for(var i=0;i<thisData.length;++i){
				$tmp.push($element.clone(true));
				$tmp[i].find("div.date").html("<em>거래일자</em>" + _util.nvl(thisData[i]["거래일자"],"-"));				 
				$tmp[i].find("div.section").html("<em>구분</em>" + _util.nvl(thisData[i]["구분"],"-"));				 
				$tmp[i].find("div.acc").html("<em>결제금액</em>" + _util.fNum(_util.nvl(thisData[i]["결재금액"],"-")));				 
				$tmp[i].find("div.rest").html("<em>적립</em>" + _util.nvl(thisData[i]["적립마일리지"],"-"));				 
				$tmp[i].find("div.sub").html("<em>결제내용</em>" + _util.nvl(thisData[i]["골프장명"],"-"));				 
				
				this.listData.push(thisData[i]);
			}
			
			this.display($tmp);
		}
		, display: function(thisData){			
			var $layer = this._HTMLDom["$layer"].find("ul");
					
			for(var i=0;i<thisData.length;++i){
				$layer.append(thisData[i]);	
			}
		}
		, reset: function(){
			this.listData = [];
			this._HTMLDom["$layer"].find("ul").empty();	
		}
		, $getBtnMileage: function(){
			return this._HTMLDom["$layer"].find("div.btn_area05 a");	
		}
		, $getBtnMore: function(){			            
			return $("section#my_mileage_view>section div.btn_area div.btn_more");
		}
		, getListCount: function(){
			if(!this.listData) return 0;
			return this.listData.length;
		}
	}

	//데이터연동		
	function clsComm_MyMilegeView(){
		this.my_mileage = null;
		this.my_mileageRequest = null;
		this.my_mileagePageData = null;
		this._init();
	}	
	clsComm_MyMilegeView.prototype = {
		_init: function(){
			this.my_mileageRequest = {
				"페이지": null
				, "검색일자": null
				, "검색기간": null	
			}
			this.my_mileagePageData = {
				"현재페이지": null
				, "전체수": null
				//, "페이지당수": 10
				//, "블럭당페이지": 1
			}
		}
//------------------------ 스코어상세조회------------------------//	
		, getMyMileageList: function(){
			var thisClass = this;
			
			var szPage = this.my_mileageRequest["페이지"];
			var szSearchStartDt = this.my_mileageRequest["검색일자"];
			var szTerm = this.my_mileageRequest["검색기간"];
			
			var objJson = new MJson();
        	var cm = new ConnectionManager();

			objJson.putClient("userid", _util.getLogin("아이디"));
        	objJson.putPub("sid", "US001");
        	objJson.putPub("servicename", "getUserMyPayList");
        	objJson.putPub("listcount", 10);
        	objJson.putPub("currpageno", szPage);
        	
        	objJson.putParameter("searchStartDate", szSearchStartDt);
        	objJson.putParameter("searchTerm", szTerm);
        		
        	cm.requestGet(objJson.getJsonString(), function(ret){
				thisClass.my_mileage = [];
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					thisClass.my_mileagePageData["전체수"] = ret["msp"]["contents"]["@totalcount"];
					
					var hole = 0;
					if(!items.length) items = new Array(items);
					for(var i=0;i<items.length;i++){
						var obj = items[i];
																		
						thisClass.my_mileage.push({
							"거래일자": _util.nvl(obj["regDate"])
							, "구분": _util.nvl(obj["mileageType"])
							, "결재금액": _util.nvl(obj["payAmt"])
							, "골프장명": _util.nvl(obj["goodName"])
							, "상태": _util.nvl(obj["rounding"])
							, "적립마일리지": _util.nvl(obj["mileageAmount"])
						})
					}
				}
				$(thisClass).trigger("evtFinishMyMileageList");
			}, function($err) {
				alert($err);
			});		
		}
		, getMyMileageData: function(){
			return this.my_mileage;	
		}
		, getMyMileagePageData: function(){
			return this.my_mileagePageData;
		}
		, setMyMileageRequest: function(key, val){
			this.my_mileageRequest[key] = val;
		}
		, getMyMileageRequest: function(key){
			return this.my_mileageRequest[key];
		}
//------------------------ 스코어상세조회------------------------//			
	}
	
	//컨트롤파일
	function MyMilegeView(){		
		this.objComm = null;		
		this.objMyMilegeView = null;			
		this.objMyMileageCalendar = null;
	};
	
	MyMilegeView.prototype = {
	    onPageShow : function() {
	    	//사용자 로그인체크
//	    	if(!document.globalObj.LOGIN_DATA.isLogin){
//	    		alert("로그인 후 사용하시기 바랍니다.");
//	    		return;
//	    	}

	    	$("a").attr("href", "").attr("data-rel", "");
	    	this._init();	    		    	
	    }
	    , _init: function(){	    		    	   
	    	this.objComm = new clsComm_MyMilegeView();
	     	this.objMyMileageCalendar = new clsMyMileageCalendar();
	     	this.objMyMilegeView = new clsMyMilegeView();
	     	
	      this.getParam();
	    	
	    	this._role();
	       
	      	this._bind();
	      	this._eventFinish();     	
	    }
	    , _start: function(){	      	
	      	//마일리지정보 조회
	      	var s = this.objMyMileageCalendar.getStartDt();
	      	var t = this.objMyMileageCalendar.getTerm();
	      	
	      	this.objComm.setMyMileageRequest("페이지", 1);
	      	this.objComm.setMyMileageRequest("검색일자", s);
	      	this.objComm.setMyMileageRequest("검색기간", t);
	     	this.objComm.getMyMileageList();
	     	this.spinStart();
	    }
	    , _eventFinish: function(){
	    	var thisClass = this;
	    	
	    	//적립마일리지목록 조회 완료이벤트
		 	$(this.objComm).bind("evtFinishMyMileageList", function(event){
		 		var thisData = thisClass.objComm.getMyMileageData();
		 		var totalCnt = thisClass.objComm.getMyMileagePageData();
		 		
		 		thisClass.objMyMilegeView.setList(thisData);
		 		thisClass.spinEnd();
		 		
		 		//더보기 버튼 
		 		if(thisClass.objMyMilegeView.getListCount() >= totalCnt["전체수"]) {
		 			thisClass.objMyMilegeView.$getBtnMore().hide();
		 		}else {
		 			thisClass.objMyMilegeView.$getBtnMore().show();
		 		}
		 	});
	    }
		 , _bind: function(){
		 	var thisClass = this;
		 	
		 	//개월수 라디오버튼
		 	thisClass.objMyMileageCalendar.$getBtnRadio().click(function(event){
		 		event.preventDefault();
		 		var s = thisClass.objMyMileageCalendar.getStartDt();
		 		var t = thisClass.objMyMileageCalendar.getTerm();		 
		 		
		 		thisClass.objMyMilegeView.reset();
		 		
		 		thisClass.objComm.setMyMileageRequest("검색일자", s);
		 		thisClass.objComm.setMyMileageRequest("검색기간", t);
		 		thisClass.objComm.getMyMileageList();
		 		thisClass.spinStart();
		 	});
		 	
		 	//더보기
		 	thisClass.objMyMilegeView.$getBtnMore().click(function(event){
		 		var page = thisClass.objComm.getMyMileageRequest("페이지");
		 		thisClass.objComm.setMyMileageRequest("페이지",(page+1));
		 		thisClass.objComm.getMyMileageList();
		 		thisClass.spinStart();
		 	});
		 			 	
		 	//메뉴
		 	$("section#my_mileage_view nav ul li a:eq(0)").click(function(event){
		 		event.preventDefault();
		 		thisClass.goNavi();
		 	});
		 	
		 	//알림
		 	$("section#my_mileage_view nav ul li:eq(1)").click(function(event){
		 		event.preventDefault();
		 		$.mobile.changePage("../inc/info_booking.html","slide",true);	
		 	});
		 }
		 , getParam: function(){
	    	
	    }
	    , _role: function(){
	    		if(!_util.getLogin("로그인")){
	    			//alert("로그인 후 이용하실 수 있습니다.");		    			
	    			this.goNavi();		
	    			return;    	
	    		}
	    		
    			this._start();	    		
	   }
		, goNavi: function(){
			$.mobile.changePage("../inc/navi.html","slide",true);
		}
	    , spinStart: function(){		
			$.mobile.showPageLoadingMsg();			
		}
		, spinEnd: function(){			
	 		$.mobile.hidePageLoadingMsg();				
		}
	}	